package com.htl.线程;

public class Test3 {
    public static void main(String[] args) {
        JoinRunnable2 joinRunnable2 = new JoinRunnable2();
        Thread thread = new Thread(joinRunnable2);
        thread.start();
        for (int i = 0; i < 100; i++) {
            if (i == 20) {
                try {
                    thread.join(8000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println(i+"-----------------------main");
        }
    }
}

/**
 *  任务类
 */
class JoinRunnable2 implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(i + "-------------------JoinRunnable2");
        }
    }
}
